package com.juzipi.demo.controller;

import com.juzipi.demo.pojo.User;
import com.juzipi.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("{id}")
    public User findById(@PathVariable("id") Integer id){
        //睡眠
//        try {
//            Thread.sleep(20000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }

        return this.userService.selectUserById(id);
    }

    @GetMapping("findAll")
    public List<User> findAll(){
        return this.userService.selectUserAll();
    }

    @GetMapping("remove")
    public String removeById(@PathVariable("id")Integer id){
        this.userService.deleteById(id);
        return "success";
    }
}
